var my_vue;
$(function() {
	$("#left").load("../common/gover-left.html");
	var userId = sessionStorage.getItem("userId");
	$(".ystep1").loadStep({
		size: "small",
		color: "green",
		steps: [{
				title: "事项选择"
			},
			{
				title: "服务选择"
			},
			{
				title: "信息录入"
			},
			{
				title: "寄件选择"
			},
			{
				title: "取件选择"
			},
			{
				title: "提交成功"
			}
		]
	});
	$(".ystep1").setStep(6);
	my_vue = new Vue({
		el: '#vue_info',
		data: {
			dto:{
			apply: {
				preCode: "",
				repoCode: "",
				legalTimeLimit: "",
				dept: "",
				repoName: "",
				commitTimeLimit: "",
				createAt: ""
			},
			brcode: '',
			centerAddress: {
				mobile: "",
				address: "",
				bus: "",
				name: ""
			}
			},
			titleName:sessionStorage.getItem('titleName')
		},
		methods: {
			finish: function() {
				window.location = "index.html"
			},
			doAgain: function() {
				window.location = "selfHelpBusinessChoose.html"
			},
			exitAttendTo: function() {
				$.openDialog({
					'title': '',
					"showClose": false,
					'width': 824,
					'height': 460,
					'url': 'selfHelpExitChoose.html'
				});
			},
			complete: function() {
				this.$http.get(gover.complete+'?t=' + new Date().getMilliseconds(), {
					userId: userId,
				}, {
					emulateJSON: true
				}).then(function(result) {
					if(result.data.success) {
						this.dto.centerAddress = result.data.centerAddress;
						this.dto.apply = result.data.apply;
						this.dto.brcode = result.data.brcode;
						print();
					} else {

					}

				}, function(result) {
					showRedMsg("","服务器正忙,请稍后重试");
				})
			}

		},
		ready: function() {
			//初始化获得总页面数和列表数据
			this.complete();
		}
	});
});

function print()
{	
	var centerName = my_vue.dto.centerAddress.name;
	var repoName = my_vue.dto.apply.repoName;
	var i = 3;
	if(repoName.length>42){
		i = 5
	}
	var repoCode = my_vue.dto.apply.repoCode;
	var preCode = my_vue.dto.apply.preCode;
	var deptName = my_vue.dto.apply.dept;
	var promiseTime = my_vue.dto.apply.commitTimeLimit;
	var ruleTime = my_vue.dto.apply.legalTimeLimit;
	var address = my_vue.dto.centerAddress.address;
	var phone = my_vue.dto.centerAddress.mobile;
	var bus = my_vue.dto.centerAddress.bus;
	var submitTime = my_vue.dto.apply.createAt;
	var imageUrl = my_vue.dto.brcode;
	console.log(imageUrl);
	
	
	/*var content = "#P|" +centerName+" #P|事项名称："+repoName
	+ " #P|事项编号："+repoCode+" #P|告知单号："+preCode
	+" #P|负责部门："+deptName + " #P|提交申请时间："+submitTime 
	+" #P|事项承诺时间："+promiseTime+ +"个工作日"+" #P|事项法定时间："+ruleTime +"个工作日"
	+" #QR|"+imageUrl
	+" #P| #P|请扫描二维码查询办件进度"+" #P|中心地址："+address + " #P|联系电话："+phone
	+" #P|公交方式："+bus;
	/*fields = 'HEAD='+centerName+'&LOGO='+imagePath+'&REPONAME='+repoName+'&REPOCODE='+repoCode+'&APPLYID='+applyId+'&DEPTNAME='+deptName
	+'&PROMISETIME='+promiseTime+'&RULETIME='+ruleTime+'&ADDRESS='+address+'&PHONE='+phone+'&BUS='+bus+'&SUBMITTIME='+submitTime;*/
	var content = {
			"HEAD" : centerName,
			"REPONAME":repoName,
			"REPOCODE":repoCode,
			"APPLYID":preCode,
			"DEPTNAME": deptName,
			"SUBMITTIME":submitTime,
			"PROMISETIME":promiseTime,
			"RULETIME":ruleTime,
			"LOGO":imageUrl,
			"ADDRESS":address,
			"PHONE":phone,
			"BUS":bus
	};
	//var template = 'GWIReceiptForm'+i;*/
	$.ajax({
        url:device.print,
        data:{
        	"content":content,
			"template": ""
        },
        async:true,
        type:'post',
        dataType :'json',
        success : function(result) {
            if(result.success){
           		$(".mailtitle2").html("办理告知单打印完毕。");
            }else{
           	 showRedMsg('',result.message);
            }
        },
        error : function(){
        	showRedMsg('','打印服务故障,请稍后重试');
            return false;
        }
    });
   }